<a href='https://github.com/angular/angular.js/edit/v1.6.x/docs/content/error/ngModel/nopromise.ngdoc?message=docs(error%2Fnopromise)%3A%20describe%20your%20change...' class='improve-docs btn btn-primary'><i class="glyphicon glyphicon-edit">&nbsp;</i>Improve this Doc</a>


<h1>Error: ngModel:nopromise
  <div><span class='hint'>No promise</span></div>
</h1>

<div>
    <pre class="minerr-errmsg" error-display="Expected asynchronous validator to return a promise but got '{0}' instead.">Expected asynchronous validator to return a promise but got '{0}' instead.</pre>
</div>

<h2>Description</h2>
<div class="description">
  <p>The return value of an async validator, must always be a promise. If you want to return a
non-promise value, you can convert it to a promise using <a href="api/ng/service/$q#resolve"><code>$q.resolve()</code></a> or
<a href="api/ng/service/$q#reject"><code>$q.reject()</code></a>.</p>
<p>Example:</p>
<pre><code>.directive(&#39;asyncValidator&#39;, function($q) {
  return {
    require: &#39;ngModel&#39;,
    link: function(scope, elem, attrs, ngModel) {
      ngModel.$asyncValidators.myAsyncValidation = function(modelValue, viewValue) {
        if (/* I don&#39;t need to hit the backend API */) {
          return $q.resolve();     // to mark as valid or
          // return $q.reject();   // to mark as invalid
        } else {
          // ...send a request to the backend and return a promise
        }
      };
    }
  };
})
</code></pre>

</div>


